$(function () {
    $("#jqGrid").jqGrid({
        url: 'sys/generator/list',
        datatype: "json",
        colModel: [			
			{ label: '表名', name: 'tableName', width: 100, key: true },
			{ label: 'Engine', name: 'engine', width: 70},
			{ label: '表备注', name: 'tableComment', width: 100 },
			{ label: '创建时间', name: 'createTime', width: 100 }
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50,100,200],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		q:{
			tableName: null
		},
        info:{
            packageName:null,
            modelName:null,
            userName:null,
        }
	},
    mounted(){
        this.getInfo();
    },
	methods: {
        getInfo: function () {
            let httpRequest = new XMLHttpRequest();//第一步：建立所需的对象
            httpRequest.open('GET', 'sys/generator/getInfo', true);//第二步：打开连接
            httpRequest.send();//第三步：发送请求  将请求参数写在URL中
            /**
             * 获取数据后的处理程序
             */
            httpRequest.onreadystatechange = function () {
                if (httpRequest.readyState === 4 && httpRequest.status === 200) {
                    let json = httpRequest.responseText;//获取到json字符串，还需解析
                    if(json){
                        vm.info = JSON.parse(json).info;
                    }
                    console.log(json);
                }
            };
        },
		query: function () {
			$("#jqGrid").jqGrid('setGridParam',{
                postData:{'tableName': vm.q.tableName},
                page:1 
            }).trigger("reloadGrid");
		},
		generator: function() {
            let info = "&packageName="+ vm.info.packageName+"&modelName="+ vm.info.modelName+"&userName="+ vm.info.userName;
            let tableNames = getSelectedRows();
            if(tableNames == null){
                return ;
            }
            location.href = "sys/generator/code?type=mybatisPlus&tables=" + tableNames.join()+info;
		},
        renrenGenerator: function() {
            let info = "&packageName="+ vm.info.packageName+"&modelName="+ vm.info.modelName+"&userName="+ vm.info.userName;
            let tableNames = getSelectedRows();
            if(tableNames == null){
                return ;
            }
            location.href = "sys/generator/code?type=origin&tables=" + tableNames.join()+info;
        },
		generatorMybatis: function() {
            let info = "&packageName="+ vm.info.packageName+"&modelName="+ vm.info.modelName+"&userName="+ vm.info.userName;
            let tableNames = getSelectedRows();
            if(tableNames == null){
                return ;
            }
            location.href = "sys/generator/code?type=mybatisXml&tables=" + tableNames.join()+info;;
		},
		generatorMybatisBase: function() {
            let info = "&packageName="+ vm.info.packageName+"&modelName="+ vm.info.modelName+"&userName="+ vm.info.userName;
            let tableNames = getSelectedRows();
            if(tableNames == null){
                return ;
            }
            location.href = "sys/generator/code?type=mybatisBaseXml&tables=" + tableNames.join()+info;;
		}
	}
});

